<?php

class Gcentrale_GfiledataController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function addfileregionalAction()
    {
        // action body
        
    	$form = new Application_Form_Ficherregional();
    	$this->view->form = $form;
    	if ($this->_request->isPost()) {
    		$formData = $this->_request->getPost();
    		if ($form->isValid($formData)) {
    			$formation = new Application_Model_DbTable_Fichierregionales();
    			$row = $formation->createRow();
    			 
    			$row->nomfichier = $form->getValue('Nom');
    			$row->description = $form->getValue('desc');
    		 
    			 
    			$result = $row->save();
    			 
    			 
    			$this->_helper->redirector("gestfileregional");
    		}
    	}
    	
    }

    public function gestfileregionalAction()
    {
        // action body   	
    	$header=array(
    			"idfichierregionales"=>"Code Formation"
    			,"nomfichier"=>"nomformation"
    			,"description"=>"Description"
    	);
    	$mapper = new Application_Model_Mapper_Fichierregionales();
    	$this->view->headercolums=$header;
    	 
    	$select=$mapper->fetchAllToArray();
    	//ajouter le requtte a la paginateur
    	$paginator = Zend_Paginator::factory($select);
    	//ajouter le nombre d'enregistrement par page
    	$paginator->setItemCountPerPage(3);
    	//ajouter la page par defaut
    	$paginator->setCurrentPageNumber($this->_getParam('page', 1));
    	//ajouter le paginateur au view
    	$this->view->paginator = $paginator;
    	
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	
    }

    public function gestfeuilleAction()
    {
        // action body
        
    	// action body
    	$header=array(
    			"idfeuilles"=>"Code"
    			,"titre"=>"Titre" 
    	);
    	$mapper = new Application_Model_Mapper_Feuilles();
    	$this->view->headercolums=$header;
    	
    	$select=$mapper->fetchListToArray("idfichierregionales= ".$this->_getParam('id'));
    	//ajouter le requtte a la paginateur
    	$paginator = Zend_Paginator::factory($select);
    	//ajouter le nombre d'enregistrement par page
    	$paginator->setItemCountPerPage(3);
    	//ajouter la page par defaut
    	$paginator->setCurrentPageNumber($this->_getParam('page', 1));
    	//ajouter le paginateur au view
    	$this->view->paginator = $paginator;
    	 
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
        
    }

    public function addfeuilleAction()
    {
        // action body
        $form=new Application_Form_Feuille();
        $this->view->form=$form;
        
        if ($this->_request->isPost()) {
        	$formData = $this->_request->getPost();
        	if ($form->isValid($formData)) {
        		$formation = new Application_Model_DbTable_Feuilles();
        		$row = $formation->createRow();
        
        		$row->titre = $form->getValue('Nom');
        		$row->idfichierregionales = $this->_request->getParam("id");
        		 
        
        		$result = $row->save();
        
        
        		$this->_helper->redirector("gestfeuille","gfiledata","gcentrale",array("id"=>$this->_request->getParam("id")));
        	}
        }
    }

    public function addcolAction()
    {
        // action body
        $form = new Application_Form_Formatfeuille();
        $this->view->form=$form;
        
        if ($this->_request->isPost()) {
        	$formData = $this->_request->getPost();
        	if ($form->isValid($formData)) {
        		$formation = new Application_Model_DbTable_Formatfichier();
        		$row = $formation->createRow();
        
        		$row->colname = $form->getValue('Nom');
        		$row->idpereformat = $form->getValue('pere');
        		$row->typecol = $form->getValue('Nom');
        		$row->validateur = $form->getValue('Nom');
        		
        		$row->idfeuilles = $this->_request->getParam("id");
        		 
        
        		$result = $row->save();
        
        
        		$this->_helper->redirector("gestcol","gfiledata","gcentrale",array("id"=>$this->_request->getParam("id")));
        	}
        }
    }

    public function gestcolAction()
    {
        // action body
        
    	// action body
    	$header=array(
    			"monidformatfichier"	=> "Code"
    			,"perecolname"		=> "Pere"
    			,"titre"		=> "Feuille"
    			,"moncolname" 			=> "Colone"
    			,"montypecol" 			=> "Type"
    			,"monvalidateur"		=> "Validateur"
    			 
    			 
    	);
    	$mapper = new Application_Model_DbTable_Formatfichier();
    	$this->view->headercolums=$header;
    	
    	$select=$mapper->select_formatfile($this->_request->getParam("id"));
    	//ajouter le requtte a la paginateur
    	$paginator = Zend_Paginator::factory($select);
    	//ajouter le nombre d'enregistrement par page
    	$paginator->setItemCountPerPage(3);
    	//ajouter la page par defaut
    	$paginator->setCurrentPageNumber($this->_getParam('page', 1));
    	//ajouter le paginateur au view
    	$this->view->paginator = $paginator;
    	 
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    }


}













